@echo off
echo ==============================================================================================
echo ==============================================================================================
echo ======================win10请在path中使用java绝对路径，不要使用变量==================================
echo ==============================================================================================
echo ==============================================================================================
set file=E:\aboutWork\autoBat\atuoAddValueToWinSystemPath\customPath.txt
set show=#
set noShow=*
set mypath=MYPATH
setlocal enabledelayedexpansion
set addToSystemPathStr=
for /f "tokens=1,2 delims==" %%l in (%file%) do (
    set key=%%l
    set value=%%m
    if "!key:~0,1!" == "%show%" (
        echo %%l
    ) else (
        if not "!key:~0,1!" == "%noShow%" (
            if not "!key!" == "%mypath%" (
                echo set !key! to be !value!
                wmic ENVIRONMENT where name="!key!" delete
                wmic ENVIRONMENT create name="!key!",username="<system>",VariableValue="!value!"
            ) else (
                echo add !value! to path. addToSystemPathStr = !addToSystemPathStr!
                if "!addToSystemPathStr!" == "" (
                    set addToSystemPathStr=;!value!
                ) else (
                    set addToSystemPathStr=!addToSystemPathStr!;!value!
                )
                echo addToSystemPathStr=!addToSystemPathStr!
            )
        ) 
        
    )
)
echo set mypathStrs to system path. mypaths=!addToSystemPathStr!
echo back up system path to %USERPROFILE%\Desktop\pathBak file.
pause
echo %Path% > %USERPROFILE%\Desktop\pathBak
setx /m "Path" "%path%!addToSystemPathStr!"
pause